#-------------------------------------------------------------------------------
# Script to run the assessment of Jack Mackerel and look at outputs
#
# By: Niels Hintzen
# Upate: 31 Aug 2011
#-------------------------------------------------------------------------------


rm(list=ls())
memory.size(4000)

  # Set libraries & source code
library(lattice)
require(PBSadmb)
library(RColorBrewer)
source("diagnostics.r")
source("ADMB2R.r")

  # Set paths
codePath    <- "C:/Users/jim/Documents/_mymods/sprfmo-sam/"
inputPath   <- "C:/Users/jim/Documents/_mymods/sprfmo-sam/"
outputPath  <- "C:/Users/jim/Documents/_mymods/sprfmo-sam/Results/"
setwd(codePath)

  # Specify control file
controlFile <- "mod1"
  getwd()
  # Run the assessment
system(paste('"jjm.exe"','-ind',paste(controlFile,".ctr",sep=""),'-nox'), wait = TRUE)
setwd("R")
  # Read in the output of the assessment
jjm.in  <- read.dat("mod1.dat","./")
jjm.out <- readList("arc/mod1_R.dat")
jjm.ypr <- readYPR("arc/mod1_yld.dat")
getwd()

  # Create the diagnostics
pdf(paste(outputPath,"summary.pdf",sep=""),height=16.6,width=12.5,pointsize = 24, bg = "white")
#pdf(paste(outputPath,"mod1 - %02d.pdf"),units = "px", height=1200,width=900,pointsize = 24, bg = "white")
trellis.par.set(fontsize=list(text=24,points=20))
diagnostics(jjm.out,jjm.in,jjm.ctrl,jjm.ypr,what=c("fit","projections","ypr"))
dev.off()


  #Write output to file
writeList(setOutputNames(jjm.out),fname=paste(controlFile,"_out.txt",sep=""),format="P")